#! /usr/bin/env python
# -*- coding: utf-8 -*-

class blogfetch:
	def get_banlist(self):
		banlist_file="banlist.txt"
		self.banlist=[]
		if os.path.isfile(banlist_file):
			f=open(banlist_file)
			g=f.readlines()
			f.close()
			for i in g:
				self.banlist.append(int(i))
		
	def update_article_list(self):
		import os, urllib2, re
		userid=self.userid

		url='http://www.sciencenet.cn/blog/user_index1.aspx?userid=%d' % userid

		newdir="user%d" % userid
		if os.path.isdir(newdir):
			pass
		else:
			os.mkdir(newdir)

		postdata_template=self.postdata_template

		print "Updating first index page ..."
		req=urllib2.Request(url)
		f=urllib2.urlopen(req)
		h = f.read()
		f.close()
		f=open("user%d/page%d.html" % (userid, 1), "w")
		f.write(h)
		f.close()

		tpage=re.findall(r'总页数：<b>(.*?)</b>', h)

		max_page=int(tpage[0])

		print 'There are totally %d page(s)' % max_page

		f=open("user%d/pagenum.txt" % userid, "w")
		f.write(str(max_page))
		f.close()

		for page in range(2, max_page+1):
				print "Updating index page %d of %d ..." % (page, max_page)
				postdata=postdata_template.replace('DDDDDDD', '%d'%page, 10)
				req=urllib2.Request(url)
				f=urllib2.urlopen(req,postdata)
				h = f.read()
				f.close()
				f=open("user%d/page%d.html" % (userid, page), "w")
				f.write(h)
				f.close()

		plist=[]
		for page in range(1, max_page+1):
				f=open("user%d/page%d.html" % (userid, page))
				g=f.read()
				f.close()
				list=re.findall(r'align="left"><a href="user_content.aspx\?id=(.*?)" target="_blank">(.*?)</a></td>', g)
				plist=plist+list
			

		f=open("user%d/posts.txt" % userid, 'w')
		for i in plist:
			f.write("%s____%s\n" % (i[0], i[1]))
		f.close()

	def fetch_articles(self):
		import os, urllib2
		userid=self.userid

		f=open("user%d/pagenum.txt" % userid)
		g=f.read()
		max_page=int(g)
		f.close()

		f=open("user%d/posts.txt" % userid, )
		g=f.readlines()
		f.close()
		num_posts=len(g)
		print num_posts

		newdir="user%d/posts/" % userid
		if os.path.isdir(newdir):
			pass
		else:
			os.mkdir(newdir)

		post_count=0
		for i in g:
			post_count=post_count+1	
			post=i.split('____')
			id=int(post[0])
			title=post[1]
			title=title[0:len(title)-1]
			
			if id in self.banlist:
				print "Article id=%d is in banlist, will not be fetched" % id
				continue

			filename="user%d/posts/id%d.html" % (userid, id)
			if os.path.isfile(filename):
				pass
			else:
				print 'Fetching article %d of %d, id=%d' % (post_count, num_posts, id)
				url='http://www.sciencenet.cn/blog/user_content.aspx?id=%d'% id
				f=urllib2.urlopen(url)
				g=f.read()
				f.close()
				f=open(filename, 'w')
				f.write(g)
				f.close()

	def generate_ebook(self):
		import re, os
		userid=self.userid
		print "Generating ebook ... "

		f=open("user%d/pagenum.txt" % userid)
		g=f.read()
		max_page=int(g)
		f.close()

		f=open("user%d/posts.txt" % userid, )
		g=f.readlines()
		f.close()

		newdir="user%d/ebook/" % userid
		if os.path.isdir(newdir):
			pass
		else:
			os.mkdir(newdir)

		# generate article html files 
		for i in g:
			post=i.split('____')
			id=int(post[0])
			title=post[1]
			title=title[0:len(title)-1]

			if id in self.banlist:
				print "Article id=%d is in banlist, will not be included" % id
				continue

			print "handeling article %d" % id

			filename="user%d/posts/id%d.html" % (userid, id)
			filename1="user%d/ebook/post%d.html" % (userid, id)
			if os.path.isfile(filename):
				f=open(filename)
				h=f.read()
				f.close()
				body=re.findall(r'<td align="left"  valign="top" style="word-wrap: break-word; font-size:14px; line-height:20px " id="myright2">(.*?)                    </td>', h, re.DOTALL)
				body=body[0]

				authordate=re.findall(r'<td align="left" valign="top"><p class="highlight2">学者(.*?) 发表于(.*?)<br>', h)
				author=authordate[0][0]
				date=authordate[0][1]
				
				category=re.findall(r'分类：(.*?)│', h)
				category=category[0]

				f=open(filename1, 'w')
				f.write('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="kxw2ebook" /> 
<title>%s</title>
</head>
<body>
'''%title
				)
				f.write("<center><h2>%s</h2><a href=\"http://www.sciencenet.cn/blog/user_content.aspx?id=%d\">原文链接</a> &nbsp; 作者 <b>%s</b>&nbsp;&nbsp; 发表日期 %s &nbsp;&nbsp; 分类于 %s<br><br></center>" % (title, id, author, date, category))
				f.write(body)
				f.write('''
		</body>
		</html>
		''')
				f.close()

		# generate table of content html file
		f=open("user%d/ebook/toc.html" % userid, 'w')

		f.write('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="generator" content="kxw2ebook" /> 
</head>
<body>
'''
		)

		for i in g:
			post=i.split('____')
			id=int(post[0])
			title=post[1]
			title=title[0:len(title)-1]

			if id in self.banlist:
				continue

			filename="post%d.html" % id
			filename_withpath="user%d/ebook/post%d.html" % (userid, id)
			if os.path.isfile(filename_withpath):
				f.write("<li><a style=\"text-decoration: none;\" target=\"content\" href=\"%s\">%s</a></li>\n" % (filename, title))

		f.write('''
		</body>
		</html>
		''')

		f.close()

		# generate welcome.html

		f=open("user%d/ebook/welcome.html" % userid, 'w')
		f.write('''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
</HEAD>
<h2>Generated by kxw2ebook</h2>
Click links on the left panel!
</HTML>
''')
		f.close()


		# generate index.html file (with frame)

		f=open("user%d/ebook/index.html" % userid, 'w')
		f.write('''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
</HEAD>
<FRAMESET cols="20%, 80%">
  <FRAME name="index" src="toc.html" scrolling=auto>
  <FRAME name="content" src="welcome.html">
  </FRAMESET>
</HTML>
''')
		f.close()


		print 'Ebook has been generated to folder user%d/ebook/ (open index.html)' % userid

	def generate_xml(self):
		import re, os

		userid=self.userid

		f=open("user%d/pagenum.txt" % userid)
		g=f.read()
		max_page=int(g)
		f.close()

		f=open("user%d/posts.txt" % userid )
		g=f.readlines()
		f.close()
		g.reverse()

		newdir="user%d/posts/" % userid
		if os.path.isdir(newdir):
			pass
		else:
			os.mkdir(newdir)

		xmlfile= open("user%d/blog.xml" % userid, 'w')
		xmlfile.write('''<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
<!-- It contains information about your blog's posts, comments, and categories. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your blog. -->

<!-- To import this information into a WordPress blog follow these steps. -->
<!-- 1. Log into that blog as an administrator. -->
<!-- 2. Go to Manage: Import in the blog's admin panels. -->
<!-- 3. Choose "WordPress" from the list. -->
<!-- 4. Upload this file using the form provided on that page. -->
<!-- 5. You will first be asked to map the authors in this export file to users -->
<!--    on the blog.  For each author, you may choose to map to an -->
<!--    existing user on the blog or to create a new user -->
<!-- 6. WordPress will then import each of the posts, comments, and categories -->
<!--    contained in this file into your blog -->

<!-- generator="wordpress/2.3.2" created="2008-06-18 06:34"-->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.0/"
>

<channel>
	<title>kxwblog</title>
	<generator>kxw2ebook</generator>
	<language>en</language>
''')

		catlist=[]
		for i in g:
			post=i.split('____')
			id=int(post[0])

			if id in self.banlist:
				print "Article id=%d is in banlist, will not be included" % id
				continue

			filename="user%d/posts/id%d.html" % (userid, id)
			if os.path.isfile(filename):
				f=open(filename)
				h=f.read()
				f.close()
			
				category=re.findall(r'分类：(.*?)│', h)
				category=category[0]
				catlist.append(category)

		catlist=list(set(catlist))

		for i in catlist:
			xmlfile.write("\t<wp:category><wp:cat_name><![CDATA[%s]]></wp:cat_name></wp:category>\n" % i)

		for i in g:
			post=i.split('____')
			id=int(post[0])

			if id in self.banlist:
				print "Article id=%d is in banlist, will not be included" % id
				continue

			title=post[1]
			title=title[0:len(title)-1]

			filename="user%d/posts/id%d.html" % (userid, id)
			if os.path.isfile(filename):
				xmlfile.write("\n<item>")
				f=open(filename)
				h=f.read()
				f.close()
				body=re.findall(r'<td align="left"  valign="top" style="word-wrap: break-word; font-size:14px; line-height:20px " id="myright2">(.*?)                    </td>', h, re.DOTALL)
				body=body[0]

				authordate=re.findall(r'<td align="left" valign="top"><p class="highlight2">学者(.*?) 发表于(.*?)<br>', h)
				author=authordate[0][0]
				if author=='':
					author='Undetermined'
				date=authordate[0][1]
				
				category=re.findall(r'分类：(.*?)│', h)
				category=category[0]
				catlist.append(category)

				xmlfile.write('''
<title>%s</title>
<dc:creator>%s</dc:creator>
<category><![CDATA[%s]]></category>
''' % (title, author, category))
				xmlfile.write('''<content:encoded><![CDATA[%s]]></content:encoded>
''' % body)

				xmlfile.write('''<wp:post_date>%s</wp:post_date>
<wp:status>publish</wp:status>
''' % date)
				xmlfile.write(self.fetch_comments(id))

				xmlfile.write('''</item>
''')

		xmlfile.write('''
</channel>
</rss>
''')
		xmlfile.close()
		print 'user%d/blog.xml has been generated and is ready to export to WordPress' % userid

	def set_userid(self, id):
		self.userid=int(id)
		self.cmt_postdata_template='__EVENTTARGET=right_2%24AspNetPager1&__EVENTARGUMENT=DDDDDDD&__VIEWSTATE=%2FwEPDwUJNDYxMDc3ODUzD2QWAgIBD2QWAgIBD2QWHAIMDxYCHgdWaXNpYmxlaGQCEA9kFgJmD2QWAmYPZBYCZg8PFgIeBFRleHQFBjEyOTQ2M2RkAhEPFgIfAGhkAhIPFgIfAGhkAhMPFgIfAGhkAhQPFgIfAGhkAhUPFgIfAGhkAhYPFgIfAG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hAumdnuW4uOaUr%2BaMgei1teiAgeW4iOS7peWPiue8lui%2BkemDqOeahOihjOWKqOOAgiDnibnliKvmmK%2FvvJo8YnI%2BCjxicj4K56eR5a2m572R5LiN5ouF5b%2BD6ZSZ6L%2BH5LuA5LmI5omA6LCT55qE6YeN5aSn55CG6K665Yib5paw5ZKM5Lyf5aSn5Y%2BR5piO77yI5YW25a6e5piv6Ieq5oiR6IeG5oOz55qE77yJ77yM5Lmf5LiN5Zyo5LmO5rCR56eR5Lus5bim5p2l55qE5omA6LCT54K55Ye76YeP44CCIDxicj4KPGJyPgror7Tlvpflpb3vvIHvvIHmuIXpmaTmiYDosJPigJzmsJHnp5HigJ3liLvkuI3lrrnnvJPjgIJkAgIPZBYCZg9kFgZmDxUEEuiHtOm7hOaMr%2BW8uuWFiOeUnyEvYmJzL1Byb2ZpbGUuYXNweD9ibG9nPTEmdWlkPTIzNTkFbGlmZWkSMjAwOC02LTEzIDE2OjQxOjUxZAIBDxUBBTcwMDg0ZAICDxUB8gbmmK%2FlkKblupTor6XorqjorrrigJzng63moLjogZrlj5jigJ3lkozigJznjrDku6PniannkIblrabigJ3nmoTliY3mj5DkuI7msJHnp5Hml6DlhbPjgILph43opoHliY3mj5DmmK%2FvvIzkvaDkuI3og73lnKjnp5HlrabnvZHigJzov4fliIbmjqjplIDigJ3kvaDnmoTng63moLjogZrlj5jlkoznjrDku6PniannkIblrabnkIborrrvvIzogIzopoHmib7mhJ%2FlhbTotqPnmoTkurrjgILotbXmgLvnvJbovpHkuI3lrabniannkIbvvIzmiJHkuZ%2FkuI3lrabniannkIbvvIzkvaDmj5DliLDnmoTmioDmnK%2Fnu4boioLmiJHku6zpg73kuI3mh4LjgILmiYDku6XvvIzljbPkvb%2FmiJHku6zmib%2ForqTkvaDnmoTnkIborrrmmK%2Fot6jkuJbnuqrnmoTlj5HnjrDkuZ%2FmsqHmnInnlKjjgILkvaDlupTor6Xmib7kuJrlhoXlkIzooYzorqjorrrvvIzku5bku6zkvJr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6LW15oC757yW77yaPGJyPgogICAg5a%2B55p2O6aOe5pWZ5o6I55qE4oCc5a6Y56eR44CB5rCR56eR77yM6IO95Y%2BR546w56eR5a2m5a6a5b6L55qE6YO95piv55yf56eR4oCd55qE5YWL6ZqG4oCc54yr6K664oCd44CC56yU6ICF5Lmf5a6M5YWo6LWe5ZCM44CC5Zyo5b2T5LuK6IO95rqQ44CB546v5aKD5oiQ5Li65YWo56S%2B5Lya5Y%2BR5bGV55qE5oum6Lev6JmO77yM546w5Luj54mp55CG5a2m5Z%2B656GA55CG6K666Z2i5Li05YWo6Z2i56qB56C055qE5YmN5aSV44CC56yU6ICF55qE44CK5qC45Yqb57qm5p2f5oOv5oCn5Yi25a%2B85Ya35qC455u05o6l5a%2B55pKe6IGa5Y%2BY5aCG44CL5Y%2BR5piO5LiT5Yip5pyJ5pyb5ZyoM%2B%2B9njXlubTlhoXojrflvpfmiJDlip%2FvvIzpgqPml7bkuZ%2FkvJrorqnkuLvmtYHlrabmtL7lv4PmnI3lj6PmnI3lnLDmjqXlj5fnrJTogIXnmoTjgIrnjrDku6PniannkIblrabnu4%2FlhbjnspLlrZDph4%2FlrZDljJbovajpgZPov5DliqjmqKHlnovpgJrop6PjgIvnmoTmlrDnjrDku6PniannkIblrabnkIborrrkvZPns7vjgII8YnI%2BCiAgICDmiYDku6XvvIzpnaLlr7nnrJTogIXku6XjgIrmoLjlipvnuqbmnZ%2Fmg6%2FmgKfliLblr7zlhrfmoLjnm7TmjqXlr7nmkp7ogZrlj5jloIbjgIvlj5HmmI7kuJPliKnkvZzkuLrmjJHmiJjnmoTmgKXlhYjplIvvvIzlj5fmjqfng63moLjogZrlj5jlt6XnqIvlrabnlYzlkoznjrDku6PniannkIblrabnlYzvvIzljbPml6Dms5Xlm57pgb%2Fov5nlnLrorrrmiJjvvIzkuZ%2FkuI3lvpfkuI3pnaLlr7nljbPlsIbpnaLkuLTnmoTlrp7pqoznu5PmnpzjgILvvIjmnKzkuJPliKnlt7Lnu4%2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tpuWPkeWxleingueahOWfuuacrOWbveetluaYr%2BWQpumZkOWItuawkeenke%2B8n%2BeslOiAheWwhuOAiuaguOWKm%2Be6puadn%2BaDr%2BaAp%2BWItuWvvOWGt%2BaguOebtOaOpeWvueaSnuiBmuWPmOWghuOAi%2BWPkeaYjuS4k%2BWIqeeahOeUs%2Bivt%2Bi1hOaWmeWSjOOAiueOsOS7o%2BeJqeeQhuWtpue7j%2BWFuOeykuWtkOmHj%2BWtkOWMlui9qOmBk%2Bi%2FkOWKqOaooeWei%2BmAmuino%2BOAi%2BeahOeOsOS7o%2BeJqeeQhuWtpuS4k%2BiRl%2BS4iue9keaOqOiNkOe7meWtpuiAheS7rOS6pOa1geaOouiuqO%2B8jOacieWQpuinpueKr%2BS6huaIkeWbveazleW%2Bi%2B%2B8nzxicj4KICAgICDlrpjnp5Hku6zlj6%2Fku6XmjIfotKPlpKfpg6jliIbnvLrkuY%2Fln7rmnKznp5HnoJTog73lipvnmoTmsJHnp5Hku6zlubLmibDlrabmnK%2FnoJTorqjjgILkvYblr7njgIrmoLjlipvnuqbmnZ%2Fmg6%2FmgKfliLblr7zlhrfmoLjnm7TmjqXlr7nmkp7ogZrlj5jloIbjgIvlj5HmmI7kuJPliKnnmoTnlLPor7fotYTmlpnlkozjgIrnjrDku6PniannkIblrabnu4%2FlhbjnspLlrZDph4%2FlrZDljJbovajpgZPov5DliqjmqKHlnovpgJrop6PjgIvnmoTnjrDku6PniannkIblrabkuJPokZfvvIzov5nkuKTlpKfns7vliJfnmoTnoJTnqbbmiJDmnpzmj5Dlh7rnmoTmjJHmiJjvvIzpmr7pgZPov57lupTmiJjnmoTli4fmsJTpg73msqHmnInlkJfvvJ%2FvvJ%2FvvJ88YnI%2BCiAgICA8YnI%2BPGZvbnQgY29sb3I9IzMwOGFlZj7ljZrkuLvlm57lpI3vvJozM%2BalvOadjumjnuaVmeaOiOeahOingueCueaIkeW%2BiOi1nuWQjOOAguWvueS6juawkeenkeaIkeS4quS6uuW%2Bi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2FkuLvkvr%2FvvIzlkozosJDvvIHlkbXlkbXvvIFkAgkPZBYCZg9kFgZmDxUEBuaUr%2BaMgSEvYmJzL1Byb2ZpbGUuYXNweD9ibG9nPTEmdWlkPTIzNTkFbGlmZWkRMjAwOC02LTkgMjA6MTY6NTlkAgEPFQEFNjg0MzJkAgIPFQGeAeaJgOiwk%2BawkeenkeS4juWumOenke%2B8jOaPreekuuenkeWtpuecn%2BeQhuS4uuecn%2BenkeOAguS9huS7u%2BS9leenkeWtpu%2B8jOmDveimgeaOpeWPl%2BWQjOihjOivhOiuru%2B8jOaOpeWPl%2BaJueivhO%2B8jOato%2BinhuS4jei2s%2BOAguWPpuWklu%2B8jOS4jeimgeaJsOawkeOAgiAzMzkzZAIKD2QWAmYPZBYGZg8VBAzlho3mrKHmlK%2FmjIEHbWFpbHRvOgtb5ri45a6iXVhZRxEyMDA4LTYtOSAxOToxMDozOWQCAQ8VAQU2ODQxNmQCAg8VAcUB56eR5a2m572R5bqU6K%2Bl5riF6Zmk5rCR56eR77yB5q%2BU5pa56K%2B077yM5p%2BQ5Liq5Zyw5pa557uP5bi45pyJ6ay85Ye65rKh77yM5bim5p2l55qE5ZCO5p6c77ya77yIMe%2B8ieS4gOiIrOeahOS6uuS8mui%2FnOemu%2BmCo%2BmHjO%2B8m%2B%2B8iDLvvInmnInog4blpKfnmoTkurrnu4%2FluLjljrvpgqPlhL%2FvvIzliKvkurrkvJrmiorku5blvZPmiJDprLzjgIJkAgYPDxYEHgtSZWNvcmRjb3VudAIpHg5DdXN0b21JbmZvVGV4dAVb6K6w5b2V5oC75pWw77yaPGI%2BNDE8L2I%2BIOaAu%2BmhteaVsO%2B8mjxiPjU8L2I%2BIOW9k%2BWJjemhte%2B8mjxmb250IGNvbG9yPSJyZWQiPjxiPjE8L2I%2BPC9mb250PmRkAggPFgIfAGhkZH5nQ6uIgjz1Xlt%2FHiOKTOSIW3Wf&Left_10%24chengname=&Left_10%24chengmi=&right_2%24AspNetPager1_input=1&right_2%24title=&right_2%24username=&right_2%24email=&right_2%24content=&right_2%24txtvalidate='


		# I don't know what the hell this is, but it works
		self.postdata_template='__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTE5MDI4MTYxNw9kFgICAw9kFgICAQ9kFhoCDQ9kFgJmD2QWAmYPZBYCZg8PFgIeBFRleHQFBjk0Njc2M2RkAg4PFgIeB1Zpc2libGVoZAIPDxYCHwFoZAIQDxYCHwFoZAIRDxYCHwFoZAISDxYCHwFoZAITDxYCHwFoZAIUDxYCHwFoZAIVDxYCHwFoZAIWDxYCHwFoZAIXDxYCHwFoZAIYDxYCHwFoFgJmD2QWAmYPZBYCZg8PFgIfAAUGOTQ2NzYzZGQCGQ9kFgQCAQ88KwALAQAPFgoeDERhdGFLZXlGaWVsZAUCaWQeCERhdGFLZXlzFh4Ch%2BkBAobpAQL76AEC2egBApLoAQLc5wEC2%2BcBArHnAQL25gECueYBAqHmAQKm5QECveQBAvnjAQLN4gECveIBArniAQKv4QECqeEBApvhAQKZ4AECkuABArLfAQKx3wECsN8BAq3fAQLn3gECzd4BAsLeAQK%2F3gEeC18hSXRlbUNvdW50Ah4eCVBhZ2VDb3VudAIBHhVfIURhdGFTb3VyY2VJdGVtQ291bnQCHmQWAmYPZBY8AgEPZBYIZg9kFgJmDxUCBTI5ODMxQOWyreWNl%2BWbreael%2BW7uuetkeeahOiJuuacr%2BeyvuiQgy0tLS3lrp3loqjlm63lj4Lop4LorrDvvIjkuInvvIlkAgEPDxYCHwAFETIwMDgtNi0yMSA2OjMxOjQyZGQCAg8PFgIfAAUCMTdkZAIDDw8WAh8ABQEwZGQCAg9kFghmD2QWAmYPFQIFMjk4MzBA5bKt5Y2X5Zut5p6X5bu6562R55qE6Im65pyv57K%2B6JCDLS0tLeWuneWiqOWbreWPguinguiusO%2B8iOS6jO%2B8iWQCAQ8PFgIfAAURMjAwOC02LTIxIDY6MTQ6MzRkZAICDw8WAh8ABQIxNGRkAgMPDxYCHwAF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8ABQMxNDNkZAIDDw8WAh8ABQEwZGQCHA9kFghmD2QWAmYPFQIFMjg0OTMn56uv5Y2I6IqC5ri46KeI6aKQ5ZKM5Zut5o6g5b2x77yI5LiA77yJZAIBDw8WAh8ABREyMDA4LTYtMTAgOTozNzozOWRkAgIPDxYCHwAFAzE0OWRkAgMPDxYCHwAFATBkZAIdD2QWCGYPZBYCZg8VAgUyODQ4MmXku7vkuJzmnaXjgIHpmYjkvJ%2FjgIHnmb3pm6rls7DnrYnokZfjgIrnvo7lm73lrqrmlL%2FljobnqIvvvJrlvbHlk43nvo7lm73nmoQyNeS4quWPuOazleWkp%2BahiOOAi%2BaPkOimgWQCAQ8PFgIfAAURMjAwOC02LTEwIDc6NTU6MzdkZAICDw8WAh8ABQMxMzVkZAIDDw8WAh8ABQEwZGQCHg9kFghmD2QWAmYPFQIFMjg0NzkY5oWO5o%2BQ5aSn5a2m57K%2B6Iux5pWZ6IKyZAIBDw8WAh8ABREyMDA4LTYtMTAgNzowMDozN2RkAgIPDxYCHwAFAzQ2MmRkAgMPDxYCHwAFAjExZGQCAw8PFgQeC1JlY29yZGNvdW50AqoPHg5DdXN0b21JbmZvVGV4dAVe6K6w5b2V5oC75pWw77yaPGI%2BMTk2MjwvYj4g5oC76aG15pWw77yaPGI%2BNjY8L2I%2BIOW9k%2BWJjemhte%2B8mjxmb250IGNvbG9yPSJyZWQiPjxiPjE8L2I%2BPC9mb250PmRkZEpZV9Ka%2Brlc8iBDJI87uqdMmh9F&right_1%24AspNetPager1_input=DDDDDDD&right_1%24AspNetPager1=%E8%B7%B3%E8%BD%AC'
	
	def fetch_comments(self, postid):
		import os, urllib2, re
		userid=self.userid

		url='http://www.sciencenet.cn/blog/user_content.aspx?id=%d' % postid

		newdir="user%d" % userid
		if os.path.isdir(newdir):
			pass
		else:
			os.mkdir(newdir)

		cmt_postdata_template=self.cmt_postdata_template


		f=open("user%d/posts/id%d.html" % (userid, postid), )
		h = f.read()
		f.close()

		cmtlist=[]

		tpage=re.findall(r'总页数：<b>(.*?)</b>', h)
		res=re.findall(r'发表评论人：<a href="(.*?)" target="_blank">(.*?)</a>(.*?)\[(.*?)\](.*?)<td align="left" valign="top" class="highlight2"  style="word-break:break-all">(.*?)\n                                    </td>', h, re.DOTALL)
		for i in res:
			cmtlist.append( [i[1], i[3],i[5]])

		max_page=int(tpage[0])
		print "Fetching %d page(s) of comments for post id = %d ..." % (max_page, postid)


		for page in range(2, max_page+1):
				postdata=cmt_postdata_template.replace('DDDDDDD', '%d'%page, 10)
				req=urllib2.Request(url)
				f=urllib2.urlopen(req,postdata)
				h = f.read()
				f.close()
				res=re.findall(r'发表评论人：<a href="(.*?)" target="_blank">(.*?)</a>(.*?)\[(.*?)\](.*?)<td align="left" valign="top" class="highlight2"  style="word-break:break-all">(.*?)\n                                    </td>', h, re.DOTALL)
				for i in res:
					cmtlist.append( [i[1], i[3],i[5]])

		cstr=''
		cmtlist.reverse()
		for i in cmtlist:
			cstr=cstr+ '<wp:comment>\n'
			cstr=cstr+ '<wp:comment_author><![CDATA[%s]]></wp:comment_author>\n' % i[0]
			cstr=cstr+ '<wp:comment_date>%s</wp:comment_date>\n' % i[1]
			cstr=cstr+ '<wp:comment_content>%s</wp:comment_content>\n' % i[2]
			cstr=cstr+ '<wp:comment_approved>1</wp:comment_approved>\n'
			cstr=cstr+ '</wp:comment>\n'

		return cstr


if __name__=='__main__':
	import os, sys
	try:
		id=raw_input("Input userid: ")
		id=int(id)
		b=blogfetch()
		b.get_banlist()
		b.set_userid(id)
		if len(sys.argv) > 1 and sys.argv[1]=='-np':
			pass
		else:
			b.update_article_list()
		b.fetch_articles()
		b.generate_ebook()
		yn=raw_input("Generate XML for Wordpress? (y/n) ")
		if yn[0]=='y' or yn[0]=='Y':
			b.generate_xml()
		print "Done everything"
		print "Press ENTER to exit"
		os.read(sys.stdin.fileno(), 1)
	except:
		print 'ERROR occurs! Please report userid to http://huichen.org/101'
		print "Press ENTER to exit"
		os.read(sys.stdin.fileno(), 1)

